package hd.util.blur;

import android.graphics.Bitmap;

/**
 * 模糊
 * <p/>
 * Created by haidy on 14/12/16.
 */
public class Blur {
    /**
     * @param a      数组
     * @param width  宽度
     * @param height 高度
     * @param radius 模糊半径
     */
    private static native void blur(int a[], int width, int height, int radius);

    static {
        System.loadLibrary("util");
    }

    /**
     * 模糊图片
     *
     * @param bmp    bitmap
     * @param radius 半径
     * @return 模糊化的bitmap
     */
    public static Bitmap getGaussBlur(Bitmap bmp, int radius) {
        int height = bmp.getHeight();
        int width = bmp.getWidth();
        Bitmap map = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
        int in[] = new int[width * height];
        bmp.getPixels(in, 0, width, 0, 0, width, height);
        for (int i = 0; i < 2; i++) {
            blur(in, width, height, radius);
            blur(in, height, width, radius);
        }
        map.setPixels(in, 0, width, 0, 0, width, height);
        return map;
    }
}
